// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/efficiency/api/EnergyQuotaApi'

import ListClass from '@api/efficiency/model/EnergyQuotaQuery'
import EditClass from '@api/efficiency/model/EnergyQuotaSaveReq'
import ChildClass from '@api/efficiency/model/EnergyQuotaDto'

const CLIENT = CORE.grpcCLIENT(Client)
const CHILDREN = [ChildClass, 'dto', 1]

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询定额分配') {
    const DTO = CORE.grpcDTO(ListClass, param)
    const resp = await CORE.grpc(TIP, CLIENT, 'energyQuotaQuery', DTO)
    const list = resp.content || []
    return [list.length, list]
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  transEdit(one, { state: { param, list } }) {
    return { ...param, dto: list }
  },
  async edit(one, TIP = '保存定额分配') {
    const DTO = CORE.grpcDTO(EditClass, one, CHILDREN)
    await CORE.grpc(TIP, CLIENT, 'energyQuotaSave', DTO)
    return CORE.grpcOK(TIP)
  },
}
